{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os.path as ops\n",
    "import csv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "train_txt = '/Users/smiffy/Documents/GitHub/TUSIMPLE/Data_Tusimple_PyTorch/training/train.txt'\n",
    "valid_txt = '/Users/smiffy/Documents/GitHub/TUSIMPLE/Data_Tusimple_PyTorch/training/val.txt'\n",
    "test_txt = '/Users/smiffy/Documents/GitHub/TUSIMPLE/Data_Tusimple_PyTorch/training/test.txt'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "out_train_txt = '/Users/smiffy/Documents/GitHub/TUSIMPLE/txt_for_gcp/train.txt'\n",
    "out_valid_txt = '/Users/smiffy/Documents/GitHub/TUSIMPLE/txt_for_gcp/val.txt'\n",
    "out_test_txt = '/Users/smiffy/Documents/GitHub/TUSIMPLE/txt_for_gcp/test.txt'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "outfile = []\n",
    "with open(train_txt, 'r') as file:\n",
    "    data = file.readlines()\n",
    "    for l in data:\n",
    "        line = l.split()\n",
    "        path_0 = line[0]\n",
    "        path_1 = line[1]\n",
    "        path_2 = line[2]\n",
    "        path_out = ops.join('/home/ecbm4040/TUSIMPLE/training', path_0.split('/')[-2], path_0.split('/')[-1]) + ' ' + ops.join('/home/ecbm4040/TUSIMPLE/training', path_1.split('/')[-2], path_1.split('/')[-1])+ ' ' + ops.join('/home/ecbm4040/TUSIMPLE/training', path_2.split('/')[-2], path_2.split('/')[-1])\n",
    "        outfile.append(path_out)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(out_train_txt, \"w\") as of:\n",
    "    # writer = csv.writer(of, delimiter='')\n",
    "    for d in outfile:\n",
    "        of.writelines(d)\n",
    "        of.writelines('\\n')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "outfile = []\n",
    "with open(valid_txt, 'r') as file:\n",
    "    data = file.readlines()\n",
    "    for l in data:\n",
    "        line = l.split()\n",
    "        path_0 = line[0]\n",
    "        path_1 = line[1]\n",
    "        path_2 = line[2]\n",
    "        path_out = ops.join('/home/ecbm4040/TUSIMPLE/training', path_0.split('/')[-2], path_0.split('/')[-1]) + ' ' + ops.join('/home/ecbm4040/TUSIMPLE/training', path_1.split('/')[-2], path_1.split('/')[-1])+ ' ' + ops.join('/home/ecbm4040/TUSIMPLE/training', path_2.split('/')[-2], path_2.split('/')[-1])\n",
    "        outfile.append(path_out)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(out_valid_txt, \"w\") as of:\n",
    "    # writer = csv.writer(of, delimiter='')\n",
    "    for d in outfile:\n",
    "        of.writelines(d)\n",
    "        of.writelines('\\n')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "outfile = []\n",
    "with open(test_txt, 'r') as file:\n",
    "    data = file.readlines()\n",
    "    for l in data:\n",
    "        line = l.split()\n",
    "        path_0 = line[0]\n",
    "        path_1 = line[1]\n",
    "        path_2 = line[2]\n",
    "        path_out = ops.join('/home/ecbm4040/TUSIMPLE/training', path_0.split('/')[-2], path_0.split('/')[-1]) + ' ' + ops.join('/home/ecbm4040/TUSIMPLE/training', path_1.split('/')[-2], path_1.split('/')[-1])+ ' ' + ops.join('/home/ecbm4040/TUSIMPLE/training', path_2.split('/')[-2], path_2.split('/')[-1])\n",
    "        outfile.append(path_out)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(out_test_txt, \"w\") as of:\n",
    "    # writer = csv.writer(of, delimiter='')\n",
    "    for d in outfile:\n",
    "        of.writelines(d)\n",
    "        of.writelines('\\n')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['/Users/smiffy/Documents/GitHub/TUSIMPLE/train_set/training/gt_image/1536.png',\n",
       " '/Users/smiffy/Documents/GitHub/TUSIMPLE/train_set/training/gt_binary_image/1536.png',\n",
       " '/Users/smiffy/Documents/GitHub/TUSIMPLE/train_set/training/gt_instance_image/1536.png']"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "line"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# For LOCAL"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "train_txt = '/Users/smiffy/Documents/GitHub/TUSIMPLE/Data_Tusimple_PyTorch/training/train.txt'\n",
    "valid_txt = '/Users/smiffy/Documents/GitHub/TUSIMPLE/Data_Tusimple_PyTorch/training/val.txt'\n",
    "test_txt = '/Users/smiffy/Documents/GitHub/TUSIMPLE/Data_Tusimple_PyTorch/training/test.txt'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "out_train_txt = '/Users/smiffy/Documents/GitHub/TUSIMPLE/txt_for_local/train.txt'\n",
    "out_valid_txt = '/Users/smiffy/Documents/GitHub/TUSIMPLE/txt_for_local/val.txt'\n",
    "out_test_txt = '/Users/smiffy/Documents/GitHub/TUSIMPLE/txt_for_local/test.txt'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "outfile = []\n",
    "with open(train_txt, 'r') as file:\n",
    "    data = file.readlines()\n",
    "    for l in data:\n",
    "        line = l.split()\n",
    "        path_0 = line[0]\n",
    "        path_1 = line[1]\n",
    "        path_2 = line[2]\n",
    "        path_out = ops.join('/Users/smiffy/Documents/GitHub/TUSIMPLE/training', path_0.split('/')[-2], path_0.split('/')[-1]) + ' ' + ops.join('/Users/smiffy/Documents/GitHub/TUSIMPLE/training', path_1.split('/')[-2], path_1.split('/')[-1])+ ' ' + ops.join('/Users/smiffy/Documents/GitHub/TUSIMPLE/training', path_2.split('/')[-2], path_2.split('/')[-1])\n",
    "        outfile.append(path_out)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(out_train_txt, \"w\") as of:\n",
    "    # writer = csv.writer(of, delimiter='')\n",
    "    for d in outfile:\n",
    "        of.writelines(d)\n",
    "        of.writelines('\\n')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "outfile = []\n",
    "with open(valid_txt, 'r') as file:\n",
    "    data = file.readlines()\n",
    "    for l in data:\n",
    "        line = l.split()\n",
    "        path_0 = line[0]\n",
    "        path_1 = line[1]\n",
    "        path_2 = line[2]\n",
    "        path_out = ops.join('/Users/smiffy/Documents/GitHub/TUSIMPLE/training', path_0.split('/')[-2], path_0.split('/')[-1]) + ' ' + ops.join('/Users/smiffy/Documents/GitHub/TUSIMPLE/training', path_1.split('/')[-2], path_1.split('/')[-1])+ ' ' + ops.join('/Users/smiffy/Documents/GitHub/TUSIMPLE/training', path_2.split('/')[-2], path_2.split('/')[-1])\n",
    "        outfile.append(path_out)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(out_valid_txt, \"w\") as of:\n",
    "    # writer = csv.writer(of, delimiter='')\n",
    "    for d in outfile:\n",
    "        of.writelines(d)\n",
    "        of.writelines('\\n')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "outfile = []\n",
    "with open(test_txt, 'r') as file:\n",
    "    data = file.readlines()\n",
    "    for l in data:\n",
    "        line = l.split()\n",
    "        path_0 = line[0]\n",
    "        path_1 = line[1]\n",
    "        path_2 = line[2]\n",
    "        path_out = ops.join('/Users/smiffy/Documents/GitHub/TUSIMPLE/training', path_0.split('/')[-2], path_0.split('/')[-1]) + ' ' + ops.join('/Users/smiffy/Documents/GitHub/TUSIMPLE/training', path_1.split('/')[-2], path_1.split('/')[-1])+ ' ' + ops.join('/Users/smiffy/Documents/GitHub/TUSIMPLE/training', path_2.split('/')[-2], path_2.split('/')[-1])\n",
    "        outfile.append(path_out)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(out_test_txt, \"w\") as of:\n",
    "    # writer = csv.writer(of, delimiter='')\n",
    "    for d in outfile:\n",
    "        of.writelines(d)\n",
    "        of.writelines('\\n')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
